public class ext_SelectReferenceValueComponent 
{
    Public String Select_Field {get; set;}
    Field_Master__c FM;
    Public Boolean disable_Update {get; set;}
    Public ApexPages.StandardController GlobalController;
    Public String location {get; set;}
    public ext_SelectReferenceValueComponent(ApexPages.StandardController controller) 
    {
        FM = new Field_Master__c();
        GlobalController = controller;
        FM = [SELECT id, Name, Reference_To__c, Referencing_Value__c FROM Field_Master__c WHERE id = :ApexPages.CurrentPage().getParameters().get('id')];
        Select_Field = FM.Referencing_Value__c;
    }
    
    Public List<SelectOption> getFields()
    {
        List<SelectOption> options = new List<SelectOption>();
        
        if(FM.Reference_To__c.substring(1, FM.Reference_To__c.Length() -1) != '')
        {
            SObject Obj = DataBase.Query('Select id FROM ' + FM.Reference_To__c.substring(1, FM.Reference_To__c.Length() -1) + ' LIMIT 1');
            
            Schema.DescribeSObjectResult fieldResult = Obj.getSObjectType().getDescribe();
            
            List<Schema.SObjectField> ple = fieldResult.fields.getMap().values();
            
            List<Field_Master__c> Field_Master_Records = new List<Field_Master__c>();
            
            for (Schema.SObjectField f : ple) 
            {
                options.add(new SelectOption(f.getDescribe().getName(), f.getDescribe().getLabel()));
            }
            disable_Update = false;
        }
        else
        {
            disable_Update = true;
            options.add(new SelectOption('', 'No Value Available'));
        }
        return options;
    }
    
    Public void apexfunc()
    {
        FM.Referencing_Value__c = Select_Field;
        Update(FM);
        //return null;
    }
}